/*************************************************************************
	> File Name: media.h
	> Author: ma6174
	> Mail: ma6174@163.com 
	> Created Time: 2021年12月09日 星期四 22时18分33秒
 ************************************************************************/

#include<iostream>
#include <string>

class Colleague;

//中介者抽象类
class Mediator
{
public:
	virtual void send(std::string message, Colleague* colleague) = 0;
};

//同事抽象类
class Colleague
{
public:
	Colleague() = default;
	Colleague(Mediator* md) : mediator(md) {}

	virtual void notify(std::string message) = 0;

protected:
	Mediator* mediator;
};

//同事具体类
class ConcreteColleague1 : public Colleague
{
public:
	using Colleague::Colleague;
	void send(std::string message)
	{
		mediator->send(message, this);
	}

	virtual void notify(std::string message)
	{
		std::cout << "同事１得到的信息:\t" << message << std::endl;
	}
};

class ConcreteColleague2 : public Colleague
{
public:
	using Colleague::Colleague;
	void send(std::string message)
	{
		mediator->send(message, this);
	}

	virtual void notify(std::string message)
	{
		std::cout << "同事２得到的信息:\t" << message << std::endl;
	}
};

//中介者具体类
class ConcreteMediator : public Mediator
{
public:
	void setColleague(Colleague* c1, Colleague* c2)
	{
		colleague1 = c1;
		colleague2 = c2;
	}

	virtual void send(std::string message, Colleague* colleague)
	{
		if (colleague == colleague1)
			colleague2->notify(message);
		else
			colleague1->notify(message);
	}

private:
	Colleague* colleague1;
	Colleague* colleague2;
};

